<?php

require_once('functions.php');
require_once('lib/database.php');
require_once('lib/nusoap.php');


// Set up nusoap
$server = new nusoap_server;
$server->configureWSDL('nhind', 'urn:nhind');
$server->wsdl->schemaTargetNamespace = 'urn:nhind';

// Define complex types
$server->wsdl->addComplexType(
	'Domain',
	'complexType',
	'struct',
	'all',
	'',
	array(
		'id' => array('name' => 'id', 'type' => 'xsd:int'),
		'domain' => array('name' => 'domain', 'type' => 'xsd:string'),
		'local' => array('name' => 'local', 'type' => 'xsd:boolean'),
	)
);

$server->wsdl->addComplexType(
	'Domains',
	'complexType',
	'array',
	'',
	'SOAP-ENC:Array',
	array(),
	array(
		array('ref'=>'SOAP-ENC:arrayType',
			'wsdl:arrayType'=>'tns:Domain[]')
	),
	'tns:Domain'
);


$server->wsdl->addComplexType(
	'Message',
	'complexType',
	'struct',
	'all',
	'',
	array(
		'id' => array('name' => 'id', 'type' => 'xsd:int'),
		'uuid' => array('name' => 'uuid', 'type' => 'xsd:string'),
		'to_domain' => array('name' => 'to_domain', 'type' => 'xsd:string'),
		'to_endpoint' => array('name' => 'to_endpoint', 'type' => 'xsd:string'),
		'raw_message' => array('name' => 'raw_message', 'type' => 'xsd:string'),
		'created_at' => array('name' => 'created_at', 'type' => 'xsd:dateTime'),
		'update_at' => array('name' => 'updated_at', 'type' => 'xsd:dateTime'),
		'from_domain' => array('name' => 'from_domain', 'type' => 'xsd:string'),
		'from_endpoint' => array('name' => 'from_endpoint', 'type' => 'xsd:string')
	)
);


$server->wsdl->addComplexType(
	'Messages',
	'complexType',
	'array',
	'',
	'SOAP-ENC:Array',
	array(),
	array(
		array('ref'=>'SOAP-ENC:arrayType',
			'wsdl:arrayType'=>'tns:Message[]')
	),
	'tns:Message'
);


/**
 * Domains
 *
 */

// Get a list of domains
$server->register('domains', 
	array(), 
	array('return'=>'tns:Domains'), 
	'nhind', 
	'nhind#domains',
	'rpc',
	'encoded',
	'Returns all domains in an array');

// Get a single domain	
$server->register('domain', 
	array('id'=>'xsd:int'), 
	array('return'=>'tns:Domain'), 
	'nhind', 
	'nhind#domain',
	'rpc',
	'encoded',
	'Returns the data for a domain');
	
// Create a new domain
$server->register('new_domain', 
	array('domain'=>'xsd:string','local'=>'xsd:bool'), 
	array('return'=>'tns:Domain'), 
	'nhind', 
	'nhind#new_domain',
	'rpc',
	'encoded',
	'Creates a new domain and returns it');
	
// Remove domain
$server->register('remove_domain', 
	array('id'=>'xsd:int'), 
	array(), 
	'nhind', 
	'nhind#remove_domain',
	'rpc',
	'encoded',
	'Remove domain');
	
// Update domain
$server->register('update_domain', 
	array('id'=>'xsd:int','domain'=>'xsd:string','local'=>'xsd:bool'), 
	array('return'=>'tns:Domain'), 
	'nhind', 
	'nhind#update_domain',
	'rpc',
	'encoded',
	'Updates a domain and returns it');


/**
 * Messages
 *
 */

$server->register('messages', 
	array('domain'=>'xsd:string','endpoint'=>'xsd:string','status'=>'xsd:string'), 
	array('return'=>'tns:Messages'), 
	'nhind', 
	'nhind#messages',
	'rpc',
	'encoded',
	'Returns all messages in an array');
 
 
 

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA: '';

$server->service($HTTP_RAW_POST_DATA);


?>
